<?php
namespace app\admin\controller;

class Member extends Admin{
    public function __construct(){
        parent::__construct();
        $this->assign("model","Member");
    }
    public function editdetails(){
        $items = input("items");
        $model = input("model");
        $this->assign("whereData", ['id' => $items]);
        $this->assign("model",$model);
        $info = model('Member')->where('id',$items)->find();
        $this->assign("info",$info);
        return $this->fetch();
    }
    public function setstatus(){
        $status = input('setstatus');
        $items = input("items");
        model("Member")->where('id',$items)->update(['status'=>$status]);
        return json(['status'=>1, 'msg'=>'操作成功']);
    }
    public function chongzhi(){
        $items = input("items");
        $model = 'OrderAmount';
        $this->assign("whereData", ['userid' => $items]);
        $this->assign("model",$model);
        $this->assign("infoid",$items);
        return $this->fetch();
    }
    public function margin(){
        $items = input("items");
        $model = 'OrderMargin';
        $this->assign("whereData", ['userid' => $items]);
        $this->assign("model",$model);
        $this->assign("infoid",$items);
        return $this->fetch();
    }
    public function zijin(){
        $items = input("items");
        $model = 'MemberAmountLog';
        $this->assign("whereData", ['userid' => $items]);
        $this->assign("model",$model);
        $this->assign("infoid",$items);
        return $this->fetch();
    }
    public function jifen(){
        $items = input("items");
        $model = 'Jifen';
        $this->assign("whereData", ['userid' => $items]);
        $this->assign("model",$model);
        $this->assign("infoid",$items);
        return $this->fetch();
    }
    public function dingdan(){
        $items = input("items");
        $model = 'Order';
        $this->assign("whereData", ['userid' => $items]);
        $this->assign("model",$model);
        $this->assign("infoid",$items);
        return $this->fetch();
    }
    public function xiadan(){
        $items = input("items");
        $model = 'Requires';
        $this->assign("whereData", ['userid' => $items]);
        $this->assign("model",$model);
        $this->assign("infoid",$items);
        return $this->fetch();
    }
    public function guanzhu(){
        $items = input("items");
        $model = 'Favorites';
        $this->assign("whereData", ['userid' => $items]);
        $this->assign("model",$model);
        $this->assign("infoid",$items);
        return $this->fetch();
    }
    public function setamount(){
        $id = input('param.id');
        $typeid = input('param.typeid');
        $this->assign("typeid",$typeid);
        $this->assign("id",$id);
        return $this->fetch();
    }
    public function amountinc(){
        $postData = input("post.postData");
        parse_str($postData,$data);
        if (!$data['price']) {
            return json(['status'=>0, 'msg'=>'金额不能为空或0']);
        }
        if (!$data['description']) {
            return json(['status'=>0, 'msg'=>'操作原因不能为空']);
        }
        if (md5($data['password']) != config('back_password')) {
            return json(['status'=>0, 'msg'=>'密码不正确']);
        }
        if ((float)$data['price'] < 0 && $data['typeid'] == 1) {
            $amount = model("Member")->where('id', $data['userid'])->value('amount');
            if ($amount + $data['price'] < 0) {
                return json(['status'=>0, 'msg'=>'该用户账户红豆余额不足']);
            }
        }
        $paytype = 10;
        if ((float)$data['price'] < 0 && $data['typeid'] == 3) {
            $margin = model("Member")->where('id', $data['userid'])->value('margin');
            if ($margin + $data['price'] < 0) {
                return json(['status'=>0, 'msg'=>'该用户账户保障金余额不足']);
            }
            $paytype = 11;
        }
        $adminid = $this->uinfo['userid'];
        $ids = model('MemberAmountLog')->add($data, $paytype, 1, $adminid, $data['typeid']);
        if ($ids) {
            return json(['status'=>1, 'msg'=>'操作成功']);
        }else{
            return json(['status'=>0, 'msg'=>'操作失败']);
        }
    }
}